<!DOCTYPE html>
<html lang="en"  xmlns:th=http://www.thymeleaf.org>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="application/javascript" th:src="@{js/jquery/jquery-3.4.1.min.js}"></script>
    <link rel="stylesheet" th:href="@{layui/css/layui.css}">
    <script type="application/javascript" th:src="@{layui/layui.all.js}"></script>
</head>
<body>
<div id="list">


</div>
</body>
<script>
    $(function () {
        initData();
    })
    function initData() {
        $.ajax({
            url:"/cdData",
            data:{},
            dataType:"json",
            type:"post",
            success:function (data) {
                layer.msg(JSON.stringify(data));
                showData(data);
            }
        })
    }

    function showData(data) {
        var html = "";
        for (var i = 0 ;i < data.length; i++) {
            var datum = data[i];
            for (var x in datum) {
                html +='<p><span> '+x+'、'+datum[x]+'</span></p>';
            }
        }
        $("#list").html(html);
        $(".answer").hide();
        var offset = sessionStorage.getItem("offsetTop");
        $(document).scrollTop(offset);
    }
    $(window).scroll(function () {
        if ($(document).scrollTop() != 0) {
            console.log($(window).scrollTop());
            sessionStorage.setItem("offsetTop", $(window).scrollTop());
        }
    })
</script>
</html>